package cn.dengta.webapp.user.vo;

import java.util.Date;
import javax.annotation.Nullable;

import cn.dengta.common.context.I18N;
import cn.dengta.common.model.APIResponse.Field;
import cn.dengta.context.model.Language;
import cn.dengta.webapp.base.vo.SourceVO;
import cn.dengta.webapp.base.vo.UserIdEncode;
import cn.dengta.webapp.user.entity.User;
import cn.dengta.webapp.user.model.Gender;
import lombok.Getter;
import lombok.Setter;
import me.codeplayer.util.StringUtil;
import me.codeplayer.util.X;

/**
 * 推荐用户
 */
@Getter
@Setter
public class RecUserVO extends SourceVO<User> implements UserIdEncode {

	/** 前端展示使用 */
	private String uId;
	/** 昵称 */
	@Field(name = "昵称")
	public String nickname;
	/** 生日 */
	protected transient Date birthday;
	/** 性别：1=男；0=女 */
	@Field(name = "性别", value = "1=男；0=女")
	public Gender gender;
	/** 用户头像 */
	@Field(name = "用户头像")
	public String avatar;
	/** 在线 */
	@Field(name = "是否在线")
	public boolean online;
	/** 第一次搭讪 */
	@Field(name = "是否第一次搭讪")
	public Boolean isFirstChat = true;
	@Field(name = "是否新人")
	public Boolean isNewcomer;
	@Field(name = "简介")
	public String slogan;
	@Field(name = "国旗")
	public String nationalFlag;
	@Field(name = "国家")
	public String national;
	@Field(name = "VIP", value = "true=是；false=否")
	public boolean vip;
	@Field(name = "视频相册地址")
	public Object photoVideo;
	@Field(name = "是否关注")
	public Boolean isFollowed;
	@Field(name = "接通率")
	public Integer dialRate;
	@Field(name = "是否需要付费")
	public Boolean needPay;
	@Field(name = "语言")
	public transient boolean hasSelfLanguage;
	/** 动态或者相册 最后3张图片 */
	public String images;
	/** 用户标签，多个逗号分隔 */
	public String useTag;
	/** 相册张数 */
	public Integer photoNum;
	/** 语言 */
	protected Language language;

	/**  是否有 hot 标识 */
	public Boolean hots;
	/** 是否有女神勋章 */
	public Boolean goddess;
	/** 是否展示视频秀 */
	public Boolean infoShowVideo;

	public static RecUserVO from(@Nullable User source) {
		RecUserVO vo = copy(source, RecUserVO::new);
		vo.setUId(source.getId().toString());
		return vo;
	}

	public boolean isRealNamed() {
		return getSource().isRealNamed();
	}

	public boolean isAvatared() {
		return getSource().isAvatared();
	}

	public String getConstellation() {
		return getSource().getConstellation();
	}

	public Integer getAge() {
		return getSource().age();
	}

	public Integer getGender() {
		return X.map(gender, Gender::getValue);
	}

	public String getLanguage_() {
		if (language == null) {
			return null;
		}
		return StringUtil.notEmpty(this.language.getLabelKey()) ? I18N.msg(this.language.getLabelKey()) : this.language.getLabel();
	}

}
